package com.longge;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-05-09 01:45
 */
public class LetterCasePermutation {

    List<String> res = new ArrayList<String>();

    public List<String> letterCasePermutation(String S) {
        char[] chars = S.toCharArray();
        backtrack(chars, 0);
        return res;
    }

    private void backtrack(char[] chars, int start) {
        while (start < chars.length && chars[start] < 'A') {
            start++;
        }
        if (start == chars.length) {
            res.add(new String(chars));
            return;
        }
        chars[start] = Character.toLowerCase(chars[start]);
        backtrack(chars, start + 1);
        char[] clone = chars.clone();
        clone[start] = Character.toUpperCase(clone[start]);
        backtrack(clone, start + 1);

    }

    public static void main(String[] args) {
        new LetterCasePermutation().letterCasePermutation("c");
    }

}
